package com.statonline.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.statonline.domain.Persona;

@Repository(value = "contactDao")
public class JPAPersonaDao implements PersonaDao {
	
	private EntityManager em = null;
	
	@PersistenceContext
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
   	public List<Persona> getContactList() {
		System.out.println("getContactList()");
		Persona contact = new Persona();
        contact.setEmail("ppbordagaray");
        contact.setFirstname("-------------");
        contact.setLastname("-------------");
        contact.setTelephone("-------------");
		em.merge(contact);
		// TODO Auto-generated method stub
		return em.createQuery("select c from Contact c order by c.id").getResultList();
		//return em.createQuery("from Contact").getResultList();
	}
	
	@Transactional(readOnly = false)
	public void saveContact(Persona contact) {
		// TODO Auto-generated method stub
		System.out.println("saveContact");
		em.merge(contact);
	}

}
